

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>3.3. Distance analysis — MDAnalysis.distances &mdash; MDAnalysis v0.7.5-devel documentation</title>
    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.7.5-devel',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within MDAnalysis v0.7.5-devel documentation"
          href="../../_static/opensearch.xml"/>
    <link rel="shortcut icon" href="../../_static/mdanalysis-logo.ico"/>
    <link rel="top" title="MDAnalysis v0.7.5-devel documentation" href="../../index.html" />
    <link rel="up" title="3. Analysis modules" href="../analysis_modules.html" />
    <link rel="next" title="3.4. Generating densities from trajectories — MDAnalysis.analysis.density" href="density.html" />
    <link rel="prev" title="3.2. Native contacts analysis — MDAnalysis.analysis.contacts" href="contacts.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="density.html" title="3.4. Generating densities from trajectories — MDAnalysis.analysis.density"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="contacts.html" title="3.2. Native contacts analysis — MDAnalysis.analysis.contacts"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../analysis_modules.html" accesskey="U">3. Analysis modules</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/mdanalysis-logo-200x150.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="contacts.html"
                        title="previous chapter">3.2. Native contacts analysis &#8212; <tt class="docutils literal docutils literal"><span class="pre">MDAnalysis.analysis.contacts</span></tt></a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="density.html"
                        title="next chapter">3.4. Generating densities from trajectories &#8212; <tt class="docutils literal docutils literal"><span class="pre">MDAnalysis.analysis.density</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/documentation_pages/analysis/distances.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-MDAnalysis.analysis.distances"></span><div class="section" id="distance-analysis-mdanalysis-distances">
<h1>3.3. Distance analysis &#8212; <tt class="xref py py-mod docutils literal"><span class="pre">MDAnalysis.distances</span></tt><a class="headerlink" href="#distance-analysis-mdanalysis-distances" title="Permalink to this headline">¶</a></h1>
<p>This module provides functions to rapidly compute distances between
atoms or groups of atoms.</p>
<dl class="function">
<dt id="MDAnalysis.analysis.distances.distance_array">
<tt class="descclassname">MDAnalysis.analysis.distances.</tt><tt class="descname">distance_array</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.distances.distance_array" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate all distances between a reference set and another configuration.</p>
<p>d = distance_array(ref,conf,box[,result=d])</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first docutils">
<dt><em>ref</em></dt>
<dd><p class="first last">reference coordinate array</p>
</dd>
<dt><em>conf</em></dt>
<dd><p class="first last">configuration coordinate array</p>
</dd>
<dt><em>box</em></dt>
<dd><p class="first last">orthorhombic unit cell dimensions (minimum image convention is applied) or None [None]</p>
</dd>
<dt><em>result</em></dt>
<dd><p class="first last">optional preallocated result array which must have the shape (len(ref),len(conf)) and dtype=numpy.float64. Avoids creating the              array which saves time when the function is called repeatedly. [None]</p>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><dl class="first last docutils">
<dt><em>d</em></dt>
<dd><p class="first last">(len(ref),len(conf)) numpy array with the distances d[i,j] between ref coordinates i and conf coordinates j</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This method is slower than it could be because internally we need to
make copies of the ref and conf arrays.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.analysis.distances.self_distance_array">
<tt class="descclassname">MDAnalysis.analysis.distances.</tt><tt class="descname">self_distance_array</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.distances.self_distance_array" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate all distances d_ij between atoms i and j within a configuration <em>ref</em>.</p>
<p>d = self_distance_array(ref,box[,result=d])</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first docutils">
<dt><em>ref</em></dt>
<dd><p class="first last">reference coordinate array with N=len(ref) coordinates</p>
</dd>
<dt><em>box</em></dt>
<dd><dl class="first last docutils">
<dt>orthorhombic unit cell dimensions (minimum image convention</dt>
<dd><p class="first last">is applied) or None [None]</p>
</dd>
</dl>
</dd>
<dt><em>result</em></dt>
<dd><dl class="first last docutils">
<dt>optional preallocated result array which must have the shape</dt>
<dd><p class="first last">(N*(N-1)/2,) and dtype <tt class="docutils literal"><span class="pre">numpy.float64</span></tt>. Avoids creating
the array which saves time when the function is called repeatedly. [None]</p>
</dd>
</dl>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><dl class="first last docutils">
<dt><em>d</em></dt>
<dd><dl class="first last docutils">
<dt>N*(N-1)/2 numpy 1D array with the distances dist[i,j] between ref</dt>
<dd><p class="first">coordinates i and j at position d[k]. Loop through d:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">N</span><span class="p">):</span>
   <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">N</span><span class="p">):</span>
       <span class="n">k</span> <span class="o">+=</span> <span class="mi">1</span>
       <span class="n">dist</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
</pre></div>
</div>
</dd>
</dl>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This method is slower than it could be because internally we need to
make copies of the coordinate arrays.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.analysis.distances.contact_matrix">
<tt class="descclassname">MDAnalysis.analysis.distances.</tt><tt class="descname">contact_matrix</tt><big>(</big><em>coord</em>, <em>cutoff=15.0</em>, <em>returntype='numpy'</em>, <em>box=None</em>, <em>progress_meter_freq=100</em>, <em>suppress_progmet=False</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.distances.contact_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates a matrix of contacts between a list of coordinates.
There is a fast, high-memory-usage version for small systems
(returntype=&#8217;numpy&#8217;), and a slower, low-memory-usage version
for larger systems (returntype=&#8217;sparse&#8217;).</p>
<p>If box dimensions are passed, then periodic boundary conditions
are applied.</p>
<p>Change progress_meter_freq to alter frequency of progress meter
updates. Or switch suppress_progmet to True to suppress it completely.</p>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.analysis.distances.dist">
<tt class="descclassname">MDAnalysis.analysis.distances.</tt><tt class="descname">dist</tt><big>(</big><em>A</em>, <em>B</em>, <em>offset=0</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.distances.dist" title="Permalink to this definition">¶</a></dt>
<dd><p>Return distance between atoms in two atom groups.</p>
<p>The distance is calculated atom-wise. The residue ids are also
returned because a typical use case is to look at CA distances
before and after an alignment. Using the <em>offset</em> keyword one can
also add a constant offset to the resids which facilitates
comparison with PDB numbering.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first docutils">
<dt><em>A</em>, <em>B</em></dt>
<dd><p class="first last"><a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup" title="MDAnalysis.core.AtomGroup.AtomGroup"><tt class="xref py py-class docutils literal"><span class="pre">AtomGroup</span></tt></a> with the
same number of atoms</p>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Keywords :</th><td class="field-body"><dl class="first docutils">
<dt><em>offset</em> <span class="classifier-delimiter">:</span> <span class="classifier">integer</span></dt>
<dd><p class="first last">The <em>offset</em> is added to <em>resids_A</em> and <em>resids_B</em> (see
below) in order to produce PDB numbers. The default is 0.</p>
</dd>
<dt><em>offset</em> <span class="classifier-delimiter">:</span> <span class="classifier">tuple</span></dt>
<dd><p class="first last"><em>offset[0]</em> is added to <em>resids_A</em> and <em>offset[1]</em> to
<em>resids_B</em>.</p>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">NumPy <cite>array([resids_A, resids_B, distances])</cite></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="density.html" title="3.4. Generating densities from trajectories — MDAnalysis.analysis.density"
             >next</a> |</li>
        <li class="right" >
          <a href="contacts.html" title="3.2. Native contacts analysis — MDAnalysis.analysis.contacts"
             >previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../analysis_modules.html" >3. Analysis modules</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2005-2011, Naveen Michaud-Agrawal, Elizabeth J. Denning, Joshua Adelman,
    Christian Beckstein (logo), David Caplan, Jan Domański, Philip Fowler,
    Joseph Goose, Benjamin Hall, Danny Parton, Tyler Reddy, Paul Rigor,
    and Oliver Beckstein.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>